home *** CD-ROM | disk | FTP | other *** search
- //Underpinnings for an Object Model
- class IUnknown {
- public:
- virtual ULONG AddRef() = 0;
- virtual ULONG Release() = 0;
- virtual HRESULT QueryInterface(
- REFIID iid, void** ppvObj) = 0;
- };
-
- //Calling a COM Object's Methods
- IMyInterface* pMy = NULL;
- if (pUnknown->QueryInterface(
- IID_IMyInterface,
- (void**)&pMy) == NOERROR){
- pMy->MyMethod(parameters);
- pMy->Release();
- }
-
- Interface Map Basics
- To implement a class using MFC's interface maps follow these steps:
- 1. Derive a class either directly or indirectly from CCmdTarget.
- 2. Use the DECLARE_INTERFACE_MAP function in the derived class
- definition.
- 3. For each interface you wish to support, use the
- BEGIN_INTERFACE_PART and END_INTERFACE_PART macros in the class
- definition.
- 4. In the implementation file, use the BEGIN_INTERFACE_MAP and
- END_INTERFACE_MAP macros to define the class's interface map.
- 5. For each IID supported, use the INTERFACE_PART macro between
- the BEGIN_INTERFACE_MAP and END_INTERFACE_MAP macros to map that IID
- to a specific "part" of your class.
- 6. Implement each of the nested classes that represent the
- interfaces you support.
- 7. Use the METHOD_PROLOGUE macro to access the parent,
- CCmdTarget-derived object.
- 8. AddRef, Release, and QueryInterface can delegate to the
- CCmdTarget implementation of these functions (ExternalAddRef,
- ExternalRelease, and ExternalQueryInterface).
-
-